package com.minimalist.common.entity.basic.po;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Table;
import com.minimalist.common.config.mybatis.InsertFullColumnHandler;
import com.minimalist.common.config.mybatis.UpdateFullColumnHandler;
import com.minimalist.common.config.mybatis.bo.BaseEntity;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 操作日志表 实体类。
 *
 * @author 11987
 * @since 2025-01-23
 */
@Table(value = "M_OPERATOR_LOG", onInsert = InsertFullColumnHandler.class
        , onUpdate = UpdateFullColumnHandler.class)
public class MOperatorLog extends BaseEntity implements Serializable{

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 操作日志ID
     */
    private Long operatorLogId;

    /**
     * 执行方法名称
     */
    private String name;

    /**
     * 请求URI
     */
    private String uri;

    /**
     * 请求方式
     */
    private String method;

    /**
     * 用户代理
     */
    private String userAgent;

    /**
     * 请求IP
     */
    private String ip;

    /**
     * 请求参数
     */
    private String params;

    /**
     * 请求时间
     */
    private LocalDateTime requestTime;

    /**
     * 请求时长(ms)
     */
    private String exceedTime;

    /**
     * 执行结果
     */
    private String result;

    /**
     * 状态  0：失败   1：成功
     */
    private Integer status;

    @Column(tenantId = true)
    private Long tenantId;

    public MOperatorLog() {
    }

    public MOperatorLog(Long operatorLogId, String name, String uri, String method, String ip, String params, LocalDateTime requestTime, String exceedTime, String result, Integer status, Long tenantId) {
        this.operatorLogId = operatorLogId;
        this.name = name;
        this.uri = uri;
        this.method = method;
        this.ip = ip;
        this.params = params;
        this.requestTime = requestTime;
        this.exceedTime = exceedTime;
        this.result = result;
        this.status = status;
        this.tenantId = tenantId;
    }

    public Long getOperatorLogId() {
        return operatorLogId;
    }

    public void setOperatorLogId(Long operatorLogId) {
        this.operatorLogId = operatorLogId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getParams() {
        return params;
    }

    public void setParams(String params) {
        this.params = params;
    }

    public LocalDateTime getRequestTime() {
        return requestTime;
    }

    public void setRequestTime(LocalDateTime requestTime) {
        this.requestTime = requestTime;
    }

    public String getExceedTime() {
        return exceedTime;
    }

    public void setExceedTime(String exceedTime) {
        this.exceedTime = exceedTime;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Long getTenantId() {
        return tenantId;
    }

    public void setTenantId(Long tenantId) {
        this.tenantId = tenantId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        MOperatorLog that = (MOperatorLog) o;
        return Objects.equals(operatorLogId, that.operatorLogId) &&
                Objects.equals(name, that.name) &&
                Objects.equals(uri, that.uri) &&
                Objects.equals(method, that.method) &&
                Objects.equals(ip, that.ip) &&
                Objects.equals(params, that.params) &&
                Objects.equals(requestTime, that.requestTime) &&
                Objects.equals(exceedTime, that.exceedTime) &&
                Objects.equals(result, that.result) &&
                Objects.equals(status, that.status) &&
                Objects.equals(tenantId, that.tenantId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), operatorLogId, name, uri, method, ip, params, requestTime, exceedTime, result, status, tenantId);
    }

    @Override
    public String toString() {
        return "MOperatorLog{" +
                "operatorLogId=" + operatorLogId +
                ", name='" + name + '\'' +
                ", uri='" + uri + '\'' +
                ", method='" + method + '\'' +
                ", ip='" + ip + '\'' +
                ", params='" + params + '\'' +
                ", requestTime=" + requestTime +
                ", exceedTime='" + exceedTime + '\'' +
                ", result='" + result + '\'' +
                ", status=" + status +
                ", tenantId=" + tenantId +
                '}';
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private Long operatorLogId;
        private String name;
        private String uri;
        private String method;
        private String ip;
        private String params;
        private LocalDateTime requestTime;
        private String exceedTime;
        private String result;
        private Integer status;
        private Long tenantId;

        public Builder operatorLogId(Long operatorLogId) {
            this.operatorLogId = operatorLogId;
            return this;
        }

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder uri(String uri) {
            this.uri = uri;
            return this;
        }

        public Builder method(String method) {
            this.method = method;
            return this;
        }

        public Builder ip(String ip) {
            this.ip = ip;
            return this;
        }

        public Builder params(String params) {
            this.params = params;
            return this;
        }

        public Builder requestTime(LocalDateTime requestTime) {
            this.requestTime = requestTime;
            return this;
        }

        public Builder exceedTime(String exceedTime) {
            this.exceedTime = exceedTime;
            return this;
        }

        public Builder result(String result) {
            this.result = result;
            return this;
        }

        public Builder status(Integer status) {
            this.status = status;
            return this;
        }

        public Builder tenantId(Long tenantId) {
            this.tenantId = tenantId;
            return this;
        }

        public MOperatorLog build() {
            return new MOperatorLog(operatorLogId, name, uri, method, ip, params, requestTime, exceedTime, result, status, tenantId);
        }
    }
}
